package com.superman.supermarket.client.view.person;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;
import com.superman.mvpframe.client.gin.XGinjector;
import com.superman.mvpframe.client.mvp.IPageViewPresenter;
import com.superman.supermarket.client.constant.OrderListTabConstants;

/**
 * 我的页面ui实现
 * 
 * @author superman
 * @version 2018年8月2日下午5:34:36
 */
public class PersonViewImpl extends Composite implements PersonView {

	interface PersonViewImplUiBinder extends UiBinder<Widget, PersonViewImpl> {
	}

	private static PersonViewImplUiBinder uiBinder = GWT.create(PersonViewImplUiBinder.class);

	@UiField
	Image headericon;
	@UiField
	FlowPanel mycoupon, myaddr, myorder, mycollection;
	// , aboutus;
	@UiField
	HTML nicknamehtml, allorder, topayorder, todelivery, toreceive, refund;

	private PersonViewPresenter presenter;

	/**
	 * 构造方法
	 * 
	 * @author superman
	 * @version 2018年8月2日 下午8:54:21
	 */
	public PersonViewImpl() {
		initWidget(uiBinder.createAndBindUi(this));

		myaddr.addDomHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				presenter.pushToAddrListPage();
			}
		}, ClickEvent.getType());

		mycollection.addDomHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				presenter.pushToCollectionPage();
			}
		}, ClickEvent.getType());

		myorder.addDomHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				presenter.pushToOrderListPage(OrderListTabConstants.ALL);
			}
		}, ClickEvent.getType());

		allorder.addDomHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				presenter.pushToOrderListPage(OrderListTabConstants.ALL);
			}
		}, ClickEvent.getType());
		topayorder.addDomHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				presenter.pushToOrderListPage(OrderListTabConstants.TO_PAY);
			}
		}, ClickEvent.getType());
		todelivery.addDomHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				presenter.pushToOrderListPage(OrderListTabConstants.TO_DELIVERY);
			}
		}, ClickEvent.getType());

		toreceive.addDomHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				presenter.pushToOrderListPage(OrderListTabConstants.TO_RECEIVE);
			}
		}, ClickEvent.getType());

		refund.addDomHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				presenter.pushToRefundListPage();
			}
		}, ClickEvent.getType());

		mycoupon.addDomHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				presenter.pushToCouponListPage();
			}
		}, ClickEvent.getType());
	}

	@Override
	public void init() {
		headericon.setUrl(XGinjector.INSTANCE.getUserModel().getIcon());
		nicknamehtml.setText(XGinjector.INSTANCE.getUserModel().getNickname());
		
		
		headericon.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				Window.Location.assign("http://www.baidu.com");
			}
		});
	}

	@Override
	public void setPageViewPresenter(IPageViewPresenter presenter) {
		this.presenter = (PersonViewPresenter) presenter;
	}

}
